import api from '../../api/login.js'
Page({
  data: {
    password: '',
  },
  onChange(e) {
    const ele = e.currentTarget.dataset.ele
    this.setData({
      [ele]: e.detail
    })
  },
  async onUpdatePassword() {
    if (this.data.password) {
      const res = await api.resetPassword(this.data)
      if (res.code === 0) {
        wx.showModal({
          title: '修改密码成功！',
          content: '你的新密码：' + this.data.password,
          confirmText: '去登陆',
          complete: (res) => {
            wx.setClipboardData({
              data: this.data.password,
              success(res) {
                wx.showToast({
                  title: '密码已复制',
                  icon: 'none'
                })
              }
            })
            if (res.confirm) {
              wx.reLaunch({
                url: '/pages/login/index',
              })
            }
          }
        })
      }
    } else {
      wx.showToast({
        title: '请填写密码',
        icon: 'none'
      });
    }
  }
})